package dontCare.gwtester.client.gwt.leakyAbstraction;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dontCare.gwtester.client.tool.SourceUrl;
import dontCare.gwtester.client.tool.UnitWidget;

public class FloatUnderflow extends UnitWidget {
	private static FloatUnderflowUiBinder uiBinder = GWT.create(FloatUnderflowUiBinder.class);
	interface FloatUnderflowUiBinder extends UiBinder<Widget, FloatUnderflow>{}
	
	@UiField Label downCount;
	
	public FloatUnderflow() {
		this.initWidget(uiBinder.createAndBindUi(this));
		final int START = 2000000000;
		int count = 0;
		for(float f = START; f<START+50; f++){
			count++;
		}
		downCount.setText(""+count);
	}
	
	@Override
	public List<String> getSourceUrl() {
		ArrayList<String> result = new ArrayList<String>();
		result.add(SourceUrl.genJava(FloatUnderflow.class));
		result.add(SourceUrl.genUiXml(FloatUnderflow.class));
		return result;
	}

	@Override
	public HTML getDescription() {
		return new HTML(
			"GWT 會以 64-bit 的浮點數來模擬 Java 中（除了 long 以外）的數字型態。" +
			"因此在 Development Mode 中迴圈不會執行，但是在 Production Mode 則會執行迴圈內容。<br />" +
			"Reference：<a href='https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsCompatibility'>GWT 文件</a>"
		);
	}

	@Override
	public String getName() {
		return "數值轉型問題";
	}
}